import apiUrls from 'common/api-urls'
import { isNull } from 'utils/ui-utils'

// const { moduleName } = require('env.cfg')

// const moduleCfg = window[moduleName]

// 空白填充
export function filterBlank(val) {
  return isNull(val) ? '-' : val;
}

// cos
export function filterCosUrl(val) {
  if (isNull(val)) {
    return ''
  }
  if (val.indexOf('http') > -1) {
    return val
  }
  return `${apiUrls.resourceUrl}${val}`;
}

export function filterNumbers(num) {
  return (num || 0).toString().replace(/(\d)(?=(?:\d{3})+$)/g, '$1,');
}

export function filterTimeToStr(val) {
  if (val) {
    const currentTime = Date.now()
    let minusTime = currentTime - new Date(val).getTime()
    minusTime = minusTime / 1000
    if (minusTime <= 60) {
      return `${Math.floor(minusTime)}秒前`
    }
    minusTime = minusTime / 60
    if (minusTime <= 60) {
      return `${Math.floor(minusTime)}分钟前`
    }
    minusTime = minusTime / 60
    if (minusTime <= 24) {
      return `${Math.floor(minusTime)}小时前`
    }
    minusTime = minusTime / 24
    if (minusTime <= 30) {
      return `${Math.floor(minusTime)}天前`
    }
    return val

  }
  return ''
}
